﻿using QModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QServices.Services
{
	public class DeviceManagerService : QMainService
	{

		public void SaveDeviceManager(DosingEquipment info)
		{
			using var db=CreateDbContext();
			if (string.IsNullOrWhiteSpace(info.ID))
			{
				info.ID = Guid.NewGuid().ToString();	
				db.Set<DosingEquipment>().Add(info);
			}
			else
			{
				db.Update(info);
			}
			db.SaveChanges();
		}

		public void UpdateSeasonalPattern(string areaName,int seasonPattern)
		{
			using var db=CreateDbContext();
			var info = db.Set<DosingEquipment>().FirstOrDefault(x => x.Region == areaName);
			if (info == null) return;
			info.SeasonalPattern = seasonPattern;
			db.SaveChanges();
		}
		public DosingEquipment GetDosingEquipment(string areaName)
		{
			using var db = CreateDbContext();
			var info=db.Set<DosingEquipment>().FirstOrDefault(x=>x.Region==areaName);
			return info;
		}

		public List<DosingEquipment> GetDosingEquipmentList()
		{
			using var db = CreateDbContext();
			var res=db.Set<DosingEquipment>().OrderBy(x=>x.Region).ToList();
			return res;
		}

	}
}
